<?php
session_start();
if ( isset($_SESSION["name"]) && $_COOKIE['PHPSESSID'] === session_id()) {
  echo "<script>window.location.href='list.php';</script>";
}
var_dump(session_id());
var_dump($_COOKIE);
var_dump($_SESSION);
?>
<html>
  <head>
	<meta charset='utf-8'/>
    <meta name="generator"
    content="HTML Tidy for HTML5 (experimental) for Windows https://github.com/w3c/tidy-html5/tree/c63cc39" />
    <title>登录首页</title>
    <link href="login.css" rel="stylesheet" type="text/css"/>
  </head>
  <body style="background-color: cadetblue;">
    <script type="text/javascript">
      function myfun(){
          check=document.cookie.indexOf("PHPSESSID");
          //check=getCookie("PHPSESSID");
          //alert(check);
          //if (check == 0){
            //window.location.href='list.php';
         // }
      }
      /*用window.onload调用myfun()*/
      // 不要括号
      window.onload = myfun;
  </script>
	<div class="denglu">
      <h1>登录</h1>

	  <form style="margin:0px;display:inline;" action='login.php' method='post'>
	    <p>用户名：<input type='text' name='name'></p>
	       密码：&nbsp&nbsp <input type='password' name='password'><br>
	    <hr>
	    <button>登录</button>
	  </form>
      <a href='regist.html'><button>注册</button></a>
  </div>
  </body>
</html>
